﻿
namespace OpenComposite.HumanActivity.Contracts.Participants
{
	public class EmailParticipant : IParticipant
	{
		#region Initialization
		public EmailParticipant()
			: this(null, null)
		{
		}
		public EmailParticipant(string emailaddress)
			: this(emailaddress, null)
		{
		}
		public EmailParticipant(string emailaddress, string name)
		{
			this.EmailAddress = emailaddress;
			this.Name = name;
		}

		#endregion

		#region Public Properties
		public string EmailAddress { get; set; }
		public string Name { get; set; }
		#endregion

		#region IParticipant Members

		public int ID
		{
			get { return -1; }
		}

		public string Display
		{
			get
			{
				if ( string.IsNullOrEmpty(this.Name) ) {
					return this.EmailAddress;
				}
				return string.Format("{0} <{1}>", this.Name, this.EmailAddress);
			}
		}

		public ParticipantType ParticipantType
		{
			get { return ParticipantType.EmailParticipant; }
		}
		public override string ToString()
		{
			return this.Display;
		}
		#endregion

		#region IEquatable<IParticipant> Members

		public bool Equals(IParticipant other)
		{
			EmailParticipant otheremail = other as EmailParticipant;
			if ( otheremail != null ) {
				return ( otheremail.EmailAddress == this.EmailAddress );
			}
			return false;
		}

		#endregion
	}
}
